package com.blb.zycommunity.controller;

import com.blb.zycommunity.entity.ResponseResult;
import com.blb.zycommunity.entity.SysRole;
import com.blb.zycommunity.entity.ZyComment;
import com.blb.zycommunity.service.IZyCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@RestController
@CrossOrigin
public class ZyCommentController {

    @Autowired
    private IZyCommentService zyCommentService;

    @GetMapping("/comments/{interactionId}")
    public ResponseResult<List<SysRole>> findAllComments(@PathVariable String interactionId){
        List<ZyComment> comments = zyCommentService.findComments(interactionId);
        return ResponseResult.ok(comments);
    }

    @PutMapping("/comment")
    public ResponseResult deleteComment(@RequestParam String commentId){
        zyCommentService.removeCommentById(commentId);
        return ResponseResult.ok("ok");
    }

    @PostMapping("/comment")
    public ResponseResult saveComment(@RequestBody ZyComment zyComment){
        zyComment.setCreateTime(LocalDateTime.now());
        zyCommentService.save(zyComment);
        return ResponseResult.ok("ok");
    }


}
